﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;

/// <summary>
///PageHelper 的摘要说明
/// </summary>
public class PageHelper
{
	public PageHelper()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}


    private static PageHelper _instance = null;
    private static object _synObj = new object();

    HttpCookie cookie = null;


    public static PageHelper Current
    {
        get
        {
            if (_instance == null)
            {
                lock (_synObj)
                {
                    if (_instance == null)
                    {
                        _instance = new PageHelper();
                        return _instance;
                    }
                }
            }

            return _instance;
        }
    }


    public void SetCookie(DataTable dt)
    {
        try
        {
            cookie = new HttpCookie(ConfigurationManager.AppSettings["COOKIE_KEY_USER"] as string);
            DateTime dtNow = DateTime.Now;
            string time = ConfigurationManager.AppSettings["COOKIE_TIME"].ToString();
            cookie.Expires.AddMinutes(double.Parse(time));


            cookie.Values["id"] = dt.Rows[0]["uid"].ToString();
            cookie.Values["name"] = dt.Rows[0]["userName"].ToString();
            cookie.Values["type"] = dt.Rows[0]["type"].ToString();
            cookie.Values["headImg"] = dt.Rows[0]["heardImg"].ToString();

            //cookie.Domain = "guide.com";
            //cookie.Path = "/";
            HttpContext.Current.Response.Cookies.Set(cookie);
            HttpContext.Current.Response.AppendCookie(cookie);
        }
        catch (Exception ex)
        {
            //Logger.WriteLog(ex.Message);
        }
    }
}